home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / ww_tv.exe / TVEDIT3.CPP < prev    next >
C/C++ Source or Header  |  1991-11-14  |  7KB  |  192 lines

  1. /*----------------------------------------------------------*/
  2. /*                                                          */
  3. /*   Turbo Vision 1.0                                       */
  4. /*   Copyright (c) 1991 by Borland International            */
  5. /*                                                          */
  6. /*   Turbo Vision TVEDIT source file                        */
  7. /*----------------------------------------------------------*/
  8.  
  9. #define Uses_TApplication
  10. #define Uses_TMenuBar
  11. #define Uses_TRect
  12. #define Uses_TSubMenu
  13. #define Uses_TKeys
  14. #define Uses_TMenuItem
  15. #define Uses_TStatusLine
  16. #define Uses_TStatusItem
  17. #define Uses_TStatusDef
  18. #define Uses_TPoint
  19. #define Uses_TEditor
  20. #define Uses_MsgBox
  21. #define Uses_TFileDialog
  22. #define Uses_TDeskTop
  23.  
  24. #include <tv.h>
  25.  
  26. #include "tvedit.h"
  27.  
  28. #include <stdarg.h>
  29. #include <strstrea.h>
  30. #include <iomanip.h>
  31.  
  32. TMenuBar *TEditorApp::initMenuBar( TRect r )
  33. {
  34.  
  35.       TSubMenu& sub1 = *new TSubMenu( "~F~ile", kbAltF ) +
  36.         *new TMenuItem( "~O~pen", cmOpen, kbF3 ) +
  37.         *new TMenuItem( "~N~ew", cmNew, kbNoKey ) +
  38.         *new TMenuItem( "~S~ave", cmSave, kbF2, hcNoContext, "F2" ) +
  39.         *new TMenuItem( "S~a~ve as...", cmSaveAs, kbNoKey ) +
  40.              newLine() +
  41.         *new TMenuItem( "~C~hange dir...", cmChangeDrct, kbNoKey ) +
  42.         *new TMenuItem( "~D~OS shell", cmDosShell, kbNoKey ) +
  43.         *new TMenuItem( "E~x~it", cmQuit, kbAltX, hcNoContext, "Alt-X" );
  44.  
  45.       TSubMenu& sub2 = *new TSubMenu( "~E~dit", kbAltE ) +
  46.         *new TMenuItem( "~U~ndo", cmUndo, kbNoKey ) +
  47.              newLine() +
  48.         *new TMenuItem( "Cu~t~", cmCut, kbShiftDel, hcNoContext, "Shift-Del" ) +
  49.         *new TMenuItem( "~C~opy", cmCopy, kbCtrlIns, hcNoContext, "Ctrl-Ins" ) +
  50.         *new TMenuItem( "~P~aste", cmPaste, kbShiftIns, hcNoContext, "Shift-Ins" ) +
  51.         *new TMenuItem( "~S~how clipboard", cmShowClip, kbNoKey ) +
  52.              newLine() +
  53.         *new TMenuItem( "~C~lear", cmClear, kbCtrlDel, hcNoContext, "Ctrl-Del" );
  54.  
  55.       TSubMenu& sub3 = *new TSubMenu( "~S~earch", kbAltS ) +
  56.         *new TMenuItem( "~F~ind...", cmFind, kbNoKey ) +
  57.         *new TMenuItem( "~R~eplace...", cmReplace, kbNoKey ) +
  58.         *new TMenuItem( "~S~earch again", cmSearchAgain, kbNoKey );
  59.  
  60.       TSubMenu& sub4 = *new TSubMenu( "~W~indows", kbAltW ) +
  61.         *new TMenuItem( "~S~ize/move",cmResize, kbCtrlF5, hcNoContext, "Ctrl-F5" ) +
  62.         *new TMenuItem( "~Z~oom", cmZoom, kbF5, hcNoContext, "F5" ) +
  63.         *new TMenuItem( "~T~ile", cmTile, kbNoKey ) +
  64.         *new TMenuItem( "C~a~scade", cmCascade, kbNoKey ) +
  65.         *new TMenuItem( "~N~ext", cmNext, kbF6, hcNoContext, "F6" ) +
  66.         *new TMenuItem( "~P~revious", cmPrev, kbShiftF6, hcNoContext, "Shift-F6" ) +
  67.         *new TMenuItem( "~C~lose", cmClose, kbAltF3, hcNoContext, "Alt-F3" );
  68.  
  69.     r.b.y = r.a.y+1;
  70.     return new TMenuBar( r, sub1 + sub2 + sub3 + sub4 );
  71. }
  72.  
  73. TStatusLine *TEditorApp::initStatusLine( TRect r )
  74. {
  75.     r.a.y = r.b.y-1;
  76.     return new TStatusLine( r,
  77.         *new TStatusDef( 0, 0xFFFF ) +
  78.             *new TStatusItem("~F2~ Save", kbF2, cmSave ) +
  79.             *new TStatusItem( "~F3~ Open", kbF3, cmOpen ) +
  80.             *new TStatusItem( "~Alt-F3~ Close", kbAltF3, cmClose ) +
  81.             *new TStatusItem( "~F5~ Zoom", kbF5, cmZoom ) +
  82.             *new TStatusItem( "~F6~ Next", kbF6, cmNext ) +
  83.             *new TStatusItem( "~F10~ Menu", kbF10, cmMenu ) +
  84.             *new TStatusItem( 0, kbCtrlF5, cmResize ) +
  85.             *new TStatusItem( "~Alt-R~ Record macro", kbAltR, cmRecord ) +
  86.             *new TStatusItem( "~Alt-P~ Play macro", kbAltP, cmPlay )
  87.             );
  88.  
  89. }
  90.  
  91. void TEditorApp::outOfMemory()
  92. {
  93.     messageBox("Not enough memory for this operation.", mfError | mfOKButton );
  94. }
  95.  
  96. typedef char *_charPtr;
  97. typedef TPoint *PPoint;
  98.  
  99. #pragma warn -rvl
  100.  
  101. ushort doEditDialog( int dialog, ... )
  102. {
  103.     va_list arg;
  104.  
  105.     char buf[80];
  106.     ostrstream os( buf, sizeof( buf ) );
  107.     switch( dialog )
  108.         {
  109.         case edOutOfMemory:
  110.             return messageBox( "Not enough memory for this operation",
  111.                                mfError | mfOKButton );
  112.         case edReadError:
  113.             {
  114.             va_start( arg, dialog );
  115.             os << "Error reading file " << va_arg( arg, _charPtr )
  116.                << "." << ends;
  117.             va_end( arg );
  118.             return messageBox( buf, mfError | mfOKButton );
  119.             }
  120.         case edWriteError:
  121.             {
  122.             va_start( arg, dialog );
  123.             os << "Error writing file " << va_arg( arg,_charPtr )
  124.                << "." << ends;
  125.             va_end( arg );
  126.             return messageBox( buf, mfError | mfOKButton );
  127.             }
  128.         case edCreateError:
  129.             {
  130.             va_start( arg, dialog );
  131.             os << "Error creating file " << va_arg( arg, _charPtr )
  132.                << "." << ends;
  133.             va_end( arg );
  134.             return messageBox( buf, mfError | mfOKButton );
  135.             }
  136.         case edSaveModify:
  137.             {
  138.             va_start( arg, dialog );
  139.             os << va_arg( arg, _charPtr )
  140.                << " has been modified. Save?" << ends;
  141.             va_end( arg );
  142.             return messageBox( buf, mfInformation | mfYesNoCancel );
  143.             }
  144.         case edSaveUntitled:
  145.             return messageBox( "Save untitled file?",
  146.                                mfInformation | mfYesNoCancel );
  147.         case edSaveAs:
  148.             {
  149.             va_start( arg, dialog );
  150.             return execDialog( new TFileDialog( "*.*",
  151.                                                 "Save file as",
  152.                                                 "~N~ame",
  153.                                                 fdOKButton,
  154.                                                 101 ), va_arg( arg, _charPtr ) );
  155.             }
  156.  
  157.         case edFind:
  158.             {
  159.             va_start( arg, dialog );
  160.             return execDialog( createFindDialog(), va_arg( arg, _charPtr ) );
  161.             }
  162.  
  163.         case edSearchFailed:
  164.             return messageBox( "Search string not found.",
  165.                                mfError | mfOKButton );
  166.         case edReplace:
  167.             {
  168.             va_start( arg, dialog );
  169.             return execDialog( createReplaceDialog(), va_arg( arg, _charPtr ) );
  170.             }
  171.  
  172.         case edReplacePrompt:
  173.             //  Avoid placing the dialog on the same line as the cursor
  174.             TRect r( 0, 1, 40, 8 );
  175.             r.move( (TProgram::deskTop->size.x-r.b.x)/2, 0 );
  176.             TPoint t = TProgram::deskTop->makeGlobal( r.b );
  177.             t.y++;
  178.             va_start( arg, dialog );
  179.             TPoint *pt = va_arg( arg, PPoint );
  180.             if( pt->y <= t.y )
  181.                 r.move( 0, TProgram::deskTop->size.y - r.b.y - 2 );
  182.             va_end( arg );
  183.             return messageBoxRect( r, "Replace this occurence?",
  184.                                    mfYesNoCancel | mfInformation );
  185.  
  186.         }
  187. }
  188.  
  189. #pragma warn .rvl
  190.  
  191.  
  192.